package com.xzx.interceptor;

import com.xzx.po.UserPO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/8/18 17:33
 */

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        UserPO user = (UserPO) request.getSession().getAttribute("user");
        if (user == null) {
            response.sendRedirect( request.getServletContext().getContextPath() + "/login");
            return false;
        }
        return true;
    }


}
